package com.ruoyi.service.quality.impl;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.domain.quality.MesQualityStandard;
import com.ruoyi.mapper.quality.MesQualityStandardMapper;
import com.ruoyi.service.quality.IMesQualityStandardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 质量检验标准Service业务层处理
 * 
 * @author ruoyi
 */
@Service
public class MesQualityStandardServiceImpl implements IMesQualityStandardService
{
    @Autowired
    private MesQualityStandardMapper mesQualityStandardMapper;

    /**
     * 查询质量检验标准
     * 
     * @param standardId 质量检验标准主键
     * @return 质量检验标准
     */
    @Override
    public MesQualityStandard selectMesQualityStandardByStandardId(Long standardId)
    {
        return mesQualityStandardMapper.selectMesQualityStandardByStandardId(standardId);
    }

    /**
     * 查询质量检验标准列表
     * 
     * @param mesQualityStandard 质量检验标准
     * @return 质量检验标准
     */
    @Override
    public List<MesQualityStandard> selectMesQualityStandardList(MesQualityStandard mesQualityStandard)
    {
        return mesQualityStandardMapper.selectMesQualityStandardList(mesQualityStandard);
    }

    /**
     * 校验工艺路线编码是否唯一
     *
     * @param standardCode 工艺路线编码
     * @return 结果
     */
    @Override
    public String checkStandardCodeUnique(String standardCode , Long standardId)
    {
        MesQualityStandard standard = mesQualityStandardMapper.checkStandardCodeUnique(standardCode,standardId);
        if (StringUtils.isNotNull(standard))
        {
            return "1"; // 编码已存在
        }
        return "0"; // 编码可用
    }

    /**
     * 根据产品ID查询质量标准列表
     * 
     * @param productId 产品ID
     * @return 质量检验标准集合
     */
    @Override
    public List<MesQualityStandard> selectStandardsByProductId(Long productId)
    {
        return mesQualityStandardMapper.selectStandardsByProductId(productId);
    }

    /**
     * 根据工序ID查询质量标准列表
     * 
     * @param processId 工序ID
     * @return 质量检验标准集合
     */
    @Override
    public List<MesQualityStandard> selectStandardsByProcessId(Long processId)
    {
        return mesQualityStandardMapper.selectStandardsByProcessId(processId);
    }

    /**
     * 查询启用状态的质量标准列表
     * 
     * @return 质量检验标准集合
     */
    @Override
    public List<MesQualityStandard> selectActiveStandards()
    {
        return mesQualityStandardMapper.selectActiveStandards();
    }

    /**
     * 新增质量检验标准
     * 
     * @param mesQualityStandard 质量检验标准
     * @return 结果
     */
    @Override
    public int insertMesQualityStandard(MesQualityStandard mesQualityStandard)
    {
        return mesQualityStandardMapper.insertMesQualityStandard(mesQualityStandard);
    }

    /**
     * 修改质量检验标准
     * 
     * @param mesQualityStandard 质量检验标准
     * @return 结果
     */
    @Override
    public int updateMesQualityStandard(MesQualityStandard mesQualityStandard)
    {
        return mesQualityStandardMapper.updateMesQualityStandard(mesQualityStandard);
    }

    /**
     * 批量删除质量检验标准
     * 
     * @param standardIds 需要删除的质量检验标准主键
     * @return 结果
     */
    @Override
    public int deleteMesQualityStandardByStandardIds(Long[] standardIds)
    {
        return mesQualityStandardMapper.deleteMesQualityStandardByStandardIds(standardIds);
    }

    /**
     * 删除质量检验标准信息
     * 
     * @param standardId 质量检验标准主键
     * @return 结果
     */
    @Override
    public int deleteMesQualityStandardByStandardId(Long standardId)
    {
        return mesQualityStandardMapper.deleteMesQualityStandardByStandardId(standardId);
    }
}